Track = function( trackData, status )
{
    this.description       = trackData.description;
    this.m_tags            = trackData.tags;
    this.filename          = trackData.filename;
    this.short_description = trackData.short_description,
    this.url_description   = trackData.url_description,
    this.track_length      = trackData.track_length,
    this.src_url           = trackData.src_url,
    
    this.m_sections = [];
    this.m_status = status;
}

//return added section of class Section
Track.prototype.addSection = function( sectionData )
{
    var section = new Section ( sectionData, this.m_status );
    this.m_sections.push(section);
    return section;
}

Track.prototype.updateLineStyles = function()
{
    for (var k = 0; k < this.m_sections.length; k++)
        this.m_sections[k].updateLineStyles();
}

Track.prototype.isNearClick = function( latlng, curZoom )
{
    for (var k = 0; k < this.m_sections.length; k++)
        if ( this.m_sections[k].isNearClick( latlng, curZoom ) )
            return true;
            
    return false;
}

Track.prototype.changeStatus = function( newStatus )
{
    if ( this.m_status == newStatus ) return;
    
    for (var k = 0; k < this.m_sections.length; k++)
        this.m_sections[k].changeStatus( newStatus );
        
    this.m_status = newStatus;
}

Track.prototype.isSelectedByTags = function( tagManager )
{
    assert(tagManager, 'isSelectedByTags: invalid tagManager');
    
    var requiredTags = tagManager.getIDsWithStateAsHash(1); //1 - required tags
    
    for (var t = 0; t < this.m_tags.length; t++)
    {
        if ( tagManager.getStateByID( this.m_tags[t] ) == 2 ) //2 - excluded tags
            return false;
            
        delete requiredTags[this.m_tags[t]];
    }
    
    for (var i in requiredTags) { return false; }
    
    return true;
}

//bounds of type GLatLngBounds
Track.prototype.isVisibleInBounds = function( bounds )
{
        for (var k = 0; k < this.m_sections.length; k++)
        if ( this.m_sections[k].isVisibleInBounds( bounds ) )
            return true;
            
    return false;
}